<template>
  <!--    贷款记录-->
  <Table :table-data="tableData" border
         :headerStyle="{backgroundColor:'#fffbed'}"
         :page="false"
         max-height="300px"
         @handleSizeChange="handleSizeChange"
         @handleCurrentChange="handleCurrentChange"
         :tableColumn="tableColumn">
    <template slot="status" slot-scope="{row}">
      {{ statusList.find(item => item.key === row.approvalResult).value }}
    </template>
  </Table>
</template>

<script>
import {loanInfo} from '@/api/order'

export default {
  props: ['routesQuery'],
  data() {
    return {
      tableData: [],
      tableColumn: [
        {label: this.$t('订单编号'), align: 'center', prop: 'loanRecordId', width: 150},
        {label: this.$t('申请时间'), align: 'center', prop: 'loanTime', width: 150},
        {label: this.$t('申请金额'), align: 'center', prop: 'loanAmount'},
        {label: this.$t('借款周期'), align: 'center', prop: 'loanTerm'},
        {label: this.$t('审批金额'), align: 'center', prop: 'passAmount'},
        {label: this.$t('还款时间'), align: 'center', prop: 'refundTime', width: 150},
        {label: this.$t('逾期天数'), align: 'center', prop: 'overdueDays'},
        {label: this.$t('订单状态'), align: 'center', prop: 'approvalResult', slot: 'status'},
      ],
      statusList: [
        {key: -1, value: this.$t('已关闭'), color: '#5e5e5e'},
        {key: 0, value: this.$t("未分配"), color: '#1200ff'},
        {key: 1, value: this.$t("审核中"), color: "#5e5e5e"},
        {key: 2, value: this.$t("拒绝"), color: "#9c0000"},
        {key: 5, value: this.$t("待打款"), color: "#009200"},
        {key: 6, value: this.$t("待还款"), color: "#ffc000"},
        {key: 8, value: this.$t("逾期"), color: "#ff0000"},
        {key: 9, value: this.$t("结清"), color: "#5e5e5e"},
      ],
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    async getList() {
      const {userId} = this.routesQuery
      const res = await loanInfo({
        userId: parseInt(userId),
        ...this.page
      })
      if (res.code === 1) {
        const {list, total} = res.data
        this.tableData = list
        this.page.total = total
      }
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.page.pageNum = val
      this.getList()
    }
  }
}
</script>

<style scoped>

</style>
